function validateAll(form){
    var ck_name = /^[A-Za-z0-9 ]{3,30}$/;
    var ck_email = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i ;
    var ck_username = /^[A-Za-z0-9_]{6,30}$/;
    var ck_password =  /^[A-Za-z0-9!@#$%^&*()_]{8,30}$/;
    var noerror = true; //condition
    
    if (!ck_username.test(form.username.value)) {
        document.getElementById("errorusername").innerHTML = 'Enter a valid username.';
        noerror = false;
    }else{
        document.getElementById("errorusername").innerHTML = '';
    }
    
    if (!ck_password.test(form.password.value)) {
        document.getElementById("errorpassword").innerHTML = 'Enter a valid password.';
        noerror = false;
    }else if(form.password.value != form.password2.value){
        document.getElementById("errorpassword2").innerHTML = 'Re-type password does not match.';
        noerror = false;
    }else{
        document.getElementById("errorpassword2").innerHTML = '';
    }

    if (!ck_name.test(form.firstname.value)) {
        document.getElementById("errorfirstname").innerHTML = 'Enter firstname.';
        noerror = false;
    }else{
        document.getElementById("errorfirstname").innerHTML = '';
    }
    
    if (!ck_name.test(form.lastname.value)) {
        document.getElementById("errorlastname").innerHTML = 'Enter lastname.';
        noerror = false;
    }else{
        document.getElementById("errorlastname").innerHTML = '';
    }

    if (!ck_email.test(form.email.value)) {
        document.getElementById("erroremail").innerHTML = 'Enter a valid e-mail address.';
        noerror = false;
    }else{
        document.getElementById("erroremail").innerHTML = '';
    }
   
    return noerror;
}

function validateAddOOTM(form){
    var noerror=true;
     var checkDesc = /^[A-Za-z0-9 ]{3,100}$/;
     var checkName = /^[A-Za-z0-9 ]/;
     var checkYear = /^[0-9]{4,4}$/;
     var checkDate = /^\d{4}$[\-](0?[1-9]|1[012])[\-](0?[1-9]|[12][0-9]|3[01])/;
     
    if (!checkYear.test(form.ootmYear.value)) {
        document.getElementById("erroryear").innerHTML = 'Please enter a valid year';
        noerror = false;
    }else{
        document.getElementById("erroryear").innerHTML = '';
    }
    
    if (form.ootmName.value.length() == 0) {
        document.getElementById("errorname").innerHTML = "Please enter a valid officer's name";
        noerror = false;
    }else{
        document.getElementById("errorname").innerHTML = '';
    }
    
    if (form.ootmDesc.value.length() == 0) {
        document.getElementById("errordesc").innerHTML = 'Please give a valid description';
        noerror = false;
    }else{
        document.getElementById("errordesc").innerHTML = '';
    }
    
    return noerror;
}


function validateAddActivity(form){
     var noerror=true;
     var checkDesc = /^[A-Za-z0-9 ]{3,100}$/;
     var checkName = /^[A-Za-z0-9 ]{3,30}$/;
     var checkYear = /^[0-9]{4,4}$/;
     var checkDate = /(\d{4})-(\d{2})-(\d{2})/;
    
    var title = form.actTitle.value;
    var desc = form.actDesc.value;
    
    if (title.length == 0) {
        document.getElementById("errortitle").innerHTML = 'Please give a title';
        noerror = false;
    }else{
        document.getElementById("errortitle").innerHTML = '';
    }
    
    if (!checkDate.test(form.actDate.value)) {
        document.getElementById("errordate").innerHTML = "Please enter a valid date";
        noerror = false;
    }else{
        document.getElementById("errordate").innerHTML = '';
    }
    
    if (desc.length == 0) {
        document.getElementById("errordesc").innerHTML = 'Please give a description';
        noerror = false;
    }else{
        document.getElementById("errordesc").innerHTML = '';
    }

    return noerror;
    } 
    
function validateAddAnn(form){
     var noerror=true;
     var checkDesc = /^[A-Za-z0-9 ]{3,100}$/;
     var checkName = /^[A-Za-z]{3,30}$/;
     var checkYear = /^[0-9]{4,4}$/;
     var checkDate = /(\d{4})-(\d{2})-(\d{2})/;
     
    if(form.annTitle.value.length == 0){
        document.getElementById("errortitle").innerHTML = 'Please enter a valid title';
        noerror = false;
    }else{
        document.getElementById("errortitle").innerHTML = '';
    }
    
    if (!checkDate.test(form.annDate.value)) {
        document.getElementById("errordate").innerHTML = "Please enter a valid date";
        noerror = false;
    }else{
        document.getElementById("errordate").innerHTML = '';
    }
    
    if (form.annDesc.value.length() == 0) {
        document.getElementById("errordesc").innerHTML = 'Please give a valid description';
        noerror = false;
    }else{
        document.getElementById("errordesc").innerHTML = '';
    }   
    return noerror;
    }  
    
function validateAddAge(form){
     var noerror=true;
     var checkDesc = /^[A-Za-z0-9 ]{3,100}$/;
     var checkName = /^[A-Za-z]{3,30}$/;
     var checkYear = /^[0-9]{4,4}$/;
     var checkDate = /(\d{4})-(\d{2})-(\d{2})/;
     
    if (form.placeAgenda.value.length() == 0) {
        document.getElementById("errorplace").innerHTML = 'Please enter a valid place';
        noerror = false;
    }else{
        document.getElementById("errorplace").innerHTML = '';
    }
    
    if (!checkDate.test(form.dateAgenda.value)) {
        document.getElementById("errordate").innerHTML = "Please enter a valid date";
        noerror = false;
    }else{
        document.getElementById("errordate").innerHTML = '';
    }
    
    if (form.descAgenda.value.length() == 0) {
        document.getElementById("errordesc").innerHTML = 'Please give a valid description';
        noerror = false;
    }else{
        document.getElementById("errordesc").innerHTML = '';
    }   
    return noerror;
    }    

function changeUsername(form){
    var ck_username = /^[A-Za-z0-9_]{6,30}$/;
    var noerror = true; //condition
    
    if (!ck_username.test(form.username.value)) {
        document.getElementById("errorusername").innerHTML = 'Enter a valid username.';
        noerror = false;
    }else{
        document.getElementById("errorusername").innerHTML = '';
    }
    return noerror;
}

function changePassword(form){
    var ck_password =  /^[A-Za-z0-9!@#$%^&*()_]{8,30}$/;
    var noerror = true; //condition
    
    if (!ck_password.test(form.password.value)) {
        document.getElementById("errorpassword").innerHTML = 'Enter a valid password.';
        noerror = false;
    }else if(form.password.value != form.password2.value){
        document.getElementById("errorpassword2").innerHTML = 'Re-type password does not match.';
        noerror = false;
    }else{
        document.getElementById("errorpassword2").innerHTML = '';
    }
    return noerror;
}